import Vue from 'vue'

Vue.mixin({
  data () {
    return {
      $dialog: {
        show: false,
        form: {},
        data: {},
        title: '',
        submitCallback: null
      }
    }
  },
  watch: {
    '$dialog.show' (val) {
      if (!val) {
        this.$set(this.$dialog, 'form', {})
        this.$set(this.$dialog, 'data', {})
        this.$set(this.$dialog, 'submitCallback', null)
      }
    }
  },
  methods: {
    $showDialog (form, callback, data) {
      this.$set(this.$dialog, 'show', true)
      this.$set(this.$dialog, 'form', form)
      this.$set(this.$dialog, 'data', data)
      this.$set(this.$dialog, 'submitCallback', callback)
    },
    $setDialogTitle (str) {
      this.$set(this.$dialog, 'title', str)
    },
    $hideDialog () {
      this.$set(this.$dialog, 'show', false)
    }
  }
})
